<template>
  <div class="newsList-root">
    <van-sticky>
      <van-nav-bar title="公告" left-arrow @click-left="$router.goBack()" />
    </van-sticky>

    <div class="list-box">
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <div
            class="item flex"
            v-for="(item, index) in listData"
            :key="index"
            @click="$router.push('/news')"
          >
            <div class="name-box">
              <div class="top">
                <div class="name">
                  <div class="flex">
                    <div>BTC</div>
                  </div>
                </div>
              </div>

              <div class="time">2021-03-16 15:23:42</div>
            </div>
          </div>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      listData: [{}, {}, {}],
      loading: false,
      finished: false,
      refreshing: false,
    };
  },
  methods: {
    onLoad() {
      // 异步更新数据
      //   setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.listData.push({});
        }
        // 加载状态结束
        this.loading = false;
      }, 1000);
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
  },
};
</script>

<style lang="scss" scoped>
.newsList-root {
  background-color: #fff;
  color: #141414;
  height: 100%;
  font-size: 0.26rem;

  .list-box {
    background-color: #fff;

    .item {
      padding: 0.3rem;
      border-bottom: 0.02rem solid #f0eeee;

      img {
        width: 0.38rem;
        height: 0.38rem;
        margin-right: 0.23rem;
      }
      .name-box {
        .top {
          display: flex;
          align-items: flex-start;
          margin-bottom: 0.15rem;
          .name {
            .flex {
              align-items: flex-end;
              margin-bottom: 0.1rem;
            }
            .code {
              text-align: left;
              font-size: 0.2rem;
            }
          }

          .state {
            font-size: 0.2rem;
            margin-left: 0.27rem;
          }
        }

        .time {
          text-align: left;
          font-size: 0.2rem;
          color: #a1a1a1;
        }
      }
    }
  }
}
</style>
